/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;


import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import database.IssuingDAO;
import database.OrderDAO;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import model.*;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Trang
 */
@Namespace("/Administration/Issue")
public class WIssueAction extends ActionSupport{
    private Order order;
    private Integer oid;
    public OrderDAO orderDAO = new OrderDAO();
    private List<Orderitem> orderitems ;
    private Map<Integer, String> fills;
    private Integer fill;
    private Integer  hidenID;
    private List<Issue> issues = new ArrayList<Issue>();

     public WIssueAction()
    {
        fills = new HashMap<Integer, String>();
        fills.put(1, " - Finished");     
        fills.put(2, " - Shipped");
    }

    public List<Issue> getIssues() {
        return issues;
    }

    public void setIssues(List<Issue> issues) {
        this.issues = issues;
    }

    

    
    public Integer getHidenID() {
        return hidenID;
    }

    public void setHidenID(Integer hidenID) {
        this.hidenID = hidenID;
    }

     
    public Integer getFill() {
        return fill;
    }

    public void setFill(Integer fill) {
        this.fill = fill;
    }

     
    public List<Orderitem> getOrderitems() {
        return orderitems;
    }

    public void setOrderitems(List<Orderitem> orderitems) {
        this.orderitems = orderitems;
    }

     
    public Map<Integer, String> getFills() {
        return fills;
    }

    public void setFills(Map<Integer, String> fills) {
        this.fills = fills;
    }
     
    
    public Integer getOid() {
        return oid;
    }

    public void setOid(Integer oid) {
        this.oid = oid;
    }
    
    

    public Order getOrder() {
        return order;
    }

    public void setOrder(Order order) {
        this.order = order;
    }  
    @Action(
            value = "edit-status/*",
            results = {
        @Result(name = "success", location = "/manageIssue/w_updateOrderStatus.jsp")},
            params = {"oid", "{1}"})
    public String CreateIssuePage() {
       Map session = ActionContext.getContext().getSession();
                
       order = orderDAO.getOrderbyID(oid);
       setHidenID(getOid());
       System.out.println(hidenID+"hidden ID");
       // orderitems = new OrderDAO().getOrderitemByOrderId(oid);
         orderitems = orderDAO.getOrderitemByOrderId(oid);
        
        return SUCCESS;
    }
     @Action(
            value = "update",
            results = {
        @Result(name = "success", location = "/manageIssue/w_issue.jsp")
         //@Result(name = "input", location = "/manageIssue/w_updateOrderStatus.jsp")
            })
    public String CreateIssue() {  
        System.out.println(hidenID+"hide"+fill);
       if(orderDAO.updateOrderStatus(getHidenID(),fill));
       issues = new IssuingDAO().getAllIssue();
           return SUCCESS;
    }
     
}
